home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-07-28 | 26.3 KB | 1,005 lines | [TEXT/MPS ] |
- /*
- File: UViewStatusInfo.cp
-
- Contains: *** put contents here ***
-
- Written by: Steve Datnow
-
- Copyright: © 1992 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- 8/24/93 SLD Add bullettext
- 8/18/93 SLD Add FixedPopup
- 4/2/93 KSS Add status bar item.
- 1/21/92 SLD *** put comment here ***
-
- To Do:
- */
-
- #ifndef __UViewStatusInfo__
- #include "UViewStatusInfo.h"
- #endif
-
- #ifndef __UMACAPPUTILITIES__
- #include "UMacAppUtilities.h"
- #endif
-
- #ifndef __UDOCUMENTSecondStomach__
- #include "UDocumentSecondStomach.h"
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __PACKAGES__
- #include <Packages.h>
- #endif
-
- #ifndef __FONTS__
- #include "Fonts.h"
- #endif
-
- #ifndef __STDIO__
- #include <StdIO.h>
- #endif
-
- /****************************** Global Initialization Procedure ******************************/
-
- #pragma segment DlgInit
-
- pascal void InitUViewStatusInfo()
- {
- // So the linker doesn't dead strip class info
- macroDontDeadStrip(TViewStrStatusInfo);
- macroDontDeadStrip(TViewNumStatusInfo);
- macroDontDeadStrip(TViewlongDateStatusInfo);
- macroDontDeadStrip(TViewshortDateStatusInfo);
- macroDontDeadStrip(TViewabbrevDateStatusInfo);
- macroDontDeadStrip(TViewTimeStatusInfo);
- macroDontDeadStrip(TViewElaspedTimeStatusInfo);
- macroDontDeadStrip(TViewlogStatusInfo);
- macroDontDeadStrip(TViewMonitorStatus);
- macroDontDeadStrip(TViewNumKilobytesStatusInfo);
- macroDontDeadStrip(TLeftFilledStatusBarView);
- macroDontDeadStrip(TMonitorButton);
- macroDontDeadStrip(TViewNumBytesStatusInfo);
-
- macroDontDeadStrip(TDialogViewConfig);
- macroDontDeadStrip(TFixedPopup);
-
- macroDontDeadStrip(TBulletEditText);
- }
-
- /***********************************|****************************************/
-
- TViewMonitorStaticText::TViewMonitorStaticText()
- {
- }
-
- /***********************************|****************************************/
-
- pascal void TViewMonitorStaticText::IViewMonitorStaticText(TView* itsSuperView,
- const VPoint& itsLocation,
- const VPoint& itsSize,
- SizeDeterminer itsHSizeDet,
- SizeDeterminer itsVSizeDet,
- ResNumber itsRsrcID,
- short itsIndex)
- {
- inherited::IStaticText ( itsSuperView, itsLocation, itsSize, itsHSizeDet, itsVSizeDet, itsRsrcID, itsIndex );
- }
-
- /***********************************|****************************************/
-
- pascal void TViewMonitorStaticText::GetText(CStr255& theText)
- {
- static Str255 gViewMonitorEmptyStaticTextStr = "\p?";
-
- if ( fDataHandle )
- CopyStr255((**((String255Handle)fDataHandle)), (Ptr)&theText);
- else
- theText = gViewMonitorEmptyStaticTextStr;
- }
-
- /***********************************|****************************************/
-
- pascal void TViewNumStatusInfo::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)
-
- {
- long theNum;
- long numSize = sizeof(theNum);
- CStr255 theValue;
- Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, numSize,typeLongInteger);
- if (gotInfo)
- NumToString(theNum, theValue);
- else
- theValue = "";
-
- SetText(theValue,kRedraw);
- inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
- }
-
- /***********************************|****************************************/
-
- pascal void TViewNumKilobytesStatusInfo::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)
-
- {
- long theNum;
- long numSize = sizeof(theNum);
- CStr255 theValue;
- Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, numSize, typeLongInteger);
- if (gotInfo)
- {
- NumToString(theNum / 1024, theValue);
- theValue += "K";
- }
- else
- theValue = " ";
-
-
- SetText(theValue,kRedraw);
- inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
- }
-
- /***********************************|****************************************/
-
- /*
- void FormatNumBytes(unsigned long num,unsigned long d,CStr255& theValue,CStr255 suffix) {
- unsigned long n;
- short l;
-
- n = num/(d/10);
-
- NumToString(n, theValue);
- l = theValue.Length();
- if (theValue[l] == '0')
- theValue[0] = l - 1;
- else
- theValue.Insert(".",theValue.Length()-1);
- theValue += suffix;
- }
- */
-
- pascal void TViewNumBytesStatusInfo::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)
-
- {
- unsigned long theNum;
- long numSize = sizeof(theNum);
- CStr255 theValue = "";
- Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, numSize, typeLongInteger);
- if (gotInfo)
- {
- if (theNum < 1024)
- NumToString(theNum,theValue);
- else if (theNum < 1048576) {
- theValue[0] = sprintf ( (char*) &theValue[1], "%.1fK", ((float) theNum ) / 1024.0);
- }
- else if (theNum < (1073741824)) {
- theValue[0] = sprintf ( (char*) &theValue[1], "%.1fMB", ((float) theNum ) / 1048576.0);
-
- }
- else {
- theValue[0] = sprintf ((char*) &theValue[1], "%.1fGB", ((float) theNum ) / 1073741824.0);
-
- }
- }
-
- SetText(theValue,kRedraw);
- inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
- }
-
- /***********************************|****************************************/
-
- pascal void TViewDateStatusInfo::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)
-
- {
- long theNum;
- long numSize = sizeof(theNum);
- CStr255 theValue;
- Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, numSize, typeLongInteger);
- if (gotInfo) {
- DateForm df = GetDateFormat();
- IUDateString(theNum,df,theValue);
- }
- else
- theValue = "";
-
- SetText(theValue,kRedraw);
- inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
- }
-
- /***********************************|****************************************/
-
- pascal void TViewTimeStatusInfo::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)
-
- {
- long theNum;
- long numSize = sizeof(theNum);
- CStr255 theValue;
- Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, numSize,typeLongInteger);
- if (gotInfo)
- IUTimeString( theNum, false, theValue);
- else
- theValue = "";
-
- SetText(theValue,kRedraw);
- inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
- }
-
- /***********************************|****************************************/
-
- pascal void TViewTimeStatusWithSecondsInfo::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)
-
- {
- long theNum;
- CStr255 theValue;
-
- Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, sizeof(theNum), typeLongInteger);
- if (gotInfo)
- IUTimeString(theNum, true, theValue);
- else
- theValue = "";
-
- SetText(theValue,kRedraw);
- inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
- }
-
- /***********************************|****************************************/
-
- pascal void TViewElaspedTimeStatusInfo::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)
-
- {
- unsigned long theNum;
- long numSize = sizeof(theNum);
- CStr255 theValue;
- Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, numSize,typeLongInteger);
- if (gotInfo) {
- long days = theNum / 86400;
- long hours = (theNum - (days*86400)) / 3600;
- long minutes = (theNum - (days*86400) - (hours*3600)) / 60;
- long seconds = theNum % 60;
- sprintf ((char*) &(theValue[1]), "%4d %2d:%02d:%02d", days, hours, minutes,seconds);
- theValue.Length() = strlen((char*) &(theValue[1]));
- for (short i=1;i <= theValue.Length();i++)
- if (theValue[i] == ' ' ) // Regular space
- theValue[i] =' '; // Option-space
- }
- else
- theValue = "";
-
- SetText(theValue,kRedraw);
- inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
- }
-
- /***********************************|****************************************/
-
- pascal void TViewElaspedTimeWithSecondsStatusInfo::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)
-
- {
- unsigned long theNum;
- CStr255 theValue;
-
- Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &theNum, sizeof(theNum), typeLongInteger);
-
- if (gotInfo) {
- long days = theNum / 86400;
- long hours = (theNum - (days*86400)) / 3600;
- long minutes = (theNum - (days*86400) - (hours*3600)) / 60;
- long seconds = theNum % 60;
- sprintf ((char*) &(theValue[1]), "%4d %2d:%02d", days, hours, minutes);
- theValue.Length() = strlen((char*) &(theValue[1]));
- for (short i=1;i <= theValue.Length();i++)
- if (theValue[i] == ' ' ) // Regular space
- theValue[i] =' '; // Option-space
- }
- else
- theValue = "";
-
- SetText(theValue,kRedraw);
- inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
- }
-
- /***********************************|****************************************/
-
- pascal DateForm TViewDateStatusInfo::GetDateFormat()
-
- {
- return longDate;
- };
-
- /***********************************|****************************************/
-
- pascal DateForm TViewlongDateStatusInfo::GetDateFormat()
-
- {
- return longDate;
- };
-
- /***********************************|****************************************/
-
- pascal DateForm TViewshortDateStatusInfo::GetDateFormat()
-
- {
- return shortDate;
- };
-
- /***********************************|****************************************/
-
- pascal DateForm TViewabbrevDateStatusInfo::GetDateFormat()
-
- {
- return abbrevDate;
- };
-
- /***********************************|****************************************/
-
- pascal void TViewStrStatusInfo::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)
-
- {
- CStr255 theText;
- long textSize = sizeof(theText);
- Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &(theText[1]),textSize,typeChar);
- if (gotInfo)
- theText.Length() = (short)textSize;
- else
- theText.Length() = 0;
-
- SetText(theText,kRedraw);
- inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
- }
-
- /***********************************|****************************************/
-
- pascal void TViewlogStatusInfo::Initialize()
-
- {
- fTextList = nil;
- inherited::Initialize();
- }
-
- /***********************************|****************************************/
-
- pascal void TViewlogStatusInfo::DoPostCreate(TDocument* /* itsDocument */)
-
- {
- FailNIL(fTextList = new TDynamicArray());
- fTextList->IDynamicArray(100,63); // Initialize with 100 elements of size 63
- DelItemFirst(fNumOfRows);
- }
-
-
- /***********************************|****************************************/
-
- pascal void TViewlogStatusInfo::IRes(TDocument* itsDocument,
- TView* itsSuperView,
- TStream* itsParams)
-
- {
- FailNIL(fTextList = new TDynamicArray());
- fTextList->IDynamicArray(100,63); // Initialize with 100 elements of size 63
- inherited::IRes(itsDocument,itsSuperView,itsParams);
- DelItemFirst(fNumOfRows);
- }
-
- /***********************************|****************************************/
-
- pascal void TViewlogStatusInfo::AddToLog(CStr255 theText)
-
- {
- short row = (short) (fTextList->GetSize()+1);
- if (row > 99) {
- fTextList->DeleteElementsAt(1,1);
- this->DelItemFirst(1);
- row--;
- }
- VRect theRect;
- CStr255 theTime;
- unsigned long secs;
- GetDateTime(secs);
- IUTimeString(secs,FALSE,theTime);
- theText = theTime + " - " + theText;
- fTextList->InsertElementsBefore(row,(void*) &theText,1);
- InsItemLast(1);
- RowToVRect(row,1,theRect);
- VPoint minToSee(theRect.GetLength(hSel),theRect.GetLength(vSel));
- RevealRect(theRect,minToSee,kRedraw);
- }
-
- /***********************************|****************************************/
-
- pascal void TViewlogStatusInfo::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)
-
- {
- CStr255 theText;
- long textSize = sizeof(theText);
- Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &(theText[1]),textSize,typeChar);
- if (gotInfo) {
- theText.Length() = (short)textSize;
- AddToLog(theText);
- }
- inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
- }
-
- /***********************************|****************************************/
-
- pascal void TViewlogStatusInfo::GetItemText(short index,
- CStr255& theText)
-
- {
- if (index>fTextList->GetSize())
- theText = "";
- else
- fTextList->GetElementsAt((ArrayIndex) index,(void*) &theText,1);
- }
-
- /***********************************|****************************************/
-
- pascal void TViewlogStatusInfo::Free()
-
- {
- delete fTextList;
- inherited::Free();
- }
-
- TLeftFilledStatusBarView::TLeftFilledStatusBarView()
- {
- fStatusBarValues.low = fStatusBarValues.high = fStatusBarValues.current = 0;
- }
-
- /***********************************|****************************************/
-
- #pragma segment MAViewRes
- pascal void TLeftFilledStatusBarView::Draw(const VRect& area)//Override
-
- {
- // Get the rectangle which encloses this view.
- CRect statusBarRect;
- GetDrawableQDRect ( statusBarRect );
-
- // Now, draw the 'left' part as a black filled rectangle.
- if (fStatusBarValues.high - fStatusBarValues.low) {
- float percentFilled = (fStatusBarValues.current / (fStatusBarValues.high - fStatusBarValues.low) );
- CRect leftHalf = statusBarRect;
- leftHalf.right = (short) (percentFilled * (leftHalf.right - leftHalf.left));
- FillRect (leftHalf, (ConstPatternParam) &qd.black);
-
- CRect rightHalf = statusBarRect;
- rightHalf.left = leftHalf.right + 1;
-
- PenNormal();
- FrameRect ( rightHalf );
- }
- else
- {
- PenNormal();
- FrameRect(statusBarRect );
- }
-
- inherited::Draw (area);
- }
-
- /***********************************|****************************************/
-
- #pragma segment MAEvtHandlerRes
- pascal void TLeftFilledStatusBarView::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)//Override
-
- {
- StatusBarValuesRec values;
- long numSize = sizeof(values);
-
- Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &values, numSize, typeLongInteger);
- if (gotInfo)
- {
- fStatusBarValues = values;
- }
- else
- {
- fStatusBarValues.low = fStatusBarValues.high = fStatusBarValues.current = 0;
- }
-
- // Invalidate the rect for the status bar item.
- CRect ourFrame;
- GetDrawableQDRect ( ourFrame );
- InvalidateRect ( ourFrame );
-
- inherited::DoUpdate (theChange, changedObject, changedBy, dependencySpace);
- }
-
- /***********************************|****************************************/
-
- pascal void TMonitorButton::DoUpdate(ChangeID theChange,
- TObject* changedObject,
- TObject* changedBy,
- TDependencySpace* dependencySpace)//Override
-
- {
- CStr255 theText;
- long textSize = sizeof(theText);
- Boolean gotInfo = ((TStatusItem*) changedObject)->GetInfo((void*) &(theText[1]),textSize,typeChar);
- if (gotInfo) {
- theText.Length() = (short)textSize;
- SetText(theText,kRedraw);
- }
- inherited::DoUpdate(theChange,changedObject,changedBy, dependencySpace);
- }
-
- pascal void TMonitorButton::DoEvent(EventNumber eventNumber, TEventHandler* source,
- TEvent* event)//Override
- {
- if (eventNumber == mButtonHit)
- ((TDocumentSecondStomach*) fDocument)->SendButtonMessage(fIdentifier);
- else
- inherited::DoEvent(eventNumber,source,event);
- }
-
- /***********************************|****************************************/
- /***********************************|****************************************/
-
- pascal CompareResult TStatusItemList::CompareElements(void* Element1, void* Element2)
-
- {
- long e1 = ((TStatusItem*)Element1)->GetID();
- long e2 = ((TStatusItem*)Element2)->GetID();
-
- if (e1 == e2)
- return kItem1EqualItem2;
- else
- if (e1 < e2)
- return kItem1LessThanItem2;
- else
- return kItem1GreaterThanItem2;
- }
-
- /***********************************|****************************************/
-
- TStatusItem::TStatusItem()
-
- {
- fDataType = typeWildCard;
- fData = nil;
- fDataSize = 0;
- }
-
- /***********************************|****************************************/
-
- pascal void TStatusItem::SetID(IDType theID)
-
- {
- fIdentifier = theID;
- }
-
- /***********************************|****************************************/
-
- pascal IDType TStatusItem::GetID()
-
- {
- return fIdentifier;
- }
-
- /***********************************|****************************************/
-
- pascal void TStatusItem::SetDescType(DescType dataType)
-
- {
- fDataType = dataType;
- }
-
- /***********************************|****************************************/
-
- pascal IDType TStatusItem::GetDescType()
-
- {
- return fDataType;
- }
-
- /***********************************|****************************************/
-
- pascal Boolean TStatusItem::GetInfo(void* data, long& dataSize, DescType desiredType)
-
- {
- if (fDataSize == 0)
- return FALSE;
-
- if (fDataSize < dataSize)
- dataSize = fDataSize;
-
- if (desiredType == GetDescType())
- {
- BlockMove ( (Ptr) fData, (Ptr) data, dataSize);
- return TRUE;
- }
- else
- { AEDesc desc;
-
- OSErr err = AECoercePtr ( GetDescType(), fData, fDataSize, desiredType, desc);
-
- if ((err == noErr) && ( desc.descriptorType == desiredType))
- {
- dataSize = GetHandleSize ( desc.dataHandle );
- BlockMove ( (Ptr) *desc.dataHandle, (Ptr) data, dataSize );
-
- if (GetDescType() == typeWildCard)
- SetInfo ( data, dataSize, desc.descriptorType );
- }
-
- AEDisposeDesc ( desc );
-
- return ( err == noErr );
- }
- }
-
- /***********************************|****************************************/
-
- pascal void TStatusItem::SetInfo(void* data, long dataSize, DescType actualType)
- {
- if (dataSize != fDataSize )
- {
- DisposePtr ( (Ptr) fData );
- fData = NewPtrClear ( dataSize );
- }
-
- if (fData)
- {
- fDataSize = dataSize;
- BlockMove ( (Ptr) data, fData, fDataSize );
- SetDescType ( actualType );
-
- Changed( 0, NULL ); // Notify all dependents
- }
- else
- Changed( 1, NULL );
- }
-
- /***********************************|****************************************/
-
- pascal void TViewMonitorStatus::Initialize() {
- fBlinkStatusTimer = TickCount();
- fOldText = "";
- inherited::Initialize();
- }
-
- /***********************************|****************************************/
-
- pascal void TViewMonitorStatus::SetText(const CStr255& theText,
- Boolean redraw)
- {
- fOldText = "";
- inherited::SetText(theText,redraw);
- }
-
- /***********************************|****************************************/
-
- pascal void TViewMonitorStatus::SuperViewChangedFrame(const VRect& oldFrame,
- const VRect& newFrame,
- Boolean invalidate)
- {
-
- VRect myFrame;
- VPoint delta;
-
- inherited::SuperViewChangedFrame(oldFrame,newFrame, invalidate);
- delta = newFrame.GetSize() - oldFrame.GetSize();
- GetFrame(myFrame);
- OffsetVRect(myFrame,0,delta.v);
- SetFrame(myFrame,kRedraw);
- }
-
- /***********************************|****************************************/
-
- pascal void TViewMonitorStatus::BlinkText()
-
- {
- unsigned long tickNow = TickCount();
- if ((tickNow - 30) > fBlinkStatusTimer) {
- fBlinkStatusTimer = tickNow;
- CStr255 currentText;
- GetText(currentText);
- if (currentText.Length() == 0) {
- if (fOldText.Length() != 0) {
- currentText = fOldText;
- inherited::SetText(currentText, kRedraw);
- }
- }
- else {
- fOldText = currentText;
- inherited::SetText("", kRedraw);
- }
- }
- }
-
- /***********************************|****************************************/
-
- pascal MenuHandle TFixedPopup::GetMenuHandle()
- {
- MenuHandle aMenu = MAGetMenu(this->GetMenuID());
- if (!aMenu)
- aMenu = GetMHandle(this->GetMenuID());
-
- return aMenu;
- }
-
- /***********************************|****************************************/
- const IDType kBulletTextBehavior = 'bult';
-
- const char kBulletChar = '•';
-
- class TBulletTextBehavior : public TBehavior
- {
- public:
- TBulletEditText* fBulletEditText;
-
- virtual pascal void IBulletTextBehavior(IDType itsIdentifier, TBulletEditText* itsEditText);
-
- virtual pascal void DoCommandKeyEvent(TToolboxEvent* event); // override
-
- virtual pascal void DoKeyEvent(TToolboxEvent* event); // override
-
- virtual pascal void DoMenuCommand(CommandNumber aCommandNumber); // override
-
- };
-
- //----------------------------------------------------------------------------------------
- #pragma segment DlgOpen
- pascal void TBulletEditText::Initialize() // Override
- {
- inherited::Initialize();
-
- fRealDataHandle = nil;
- fBulletTextBehavior = nil;
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment DlgClose
- pascal void TBulletEditText::Free() // Override
- {
- fRealDataHandle = (CStringHandle)DisposeIfHandle((Handle)fRealDataHandle);
- TBehavior* aBehavior = fBulletTextBehavior; // free it after inherited Free
-
- inherited::Free();
-
- FreeIfObject(aBehavior);
- }
-
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
- pascal TDialogTEView* TBulletEditText::GetTEView() // Override
- {
- if (!fBulletTextBehavior) {
- TBulletTextBehavior* aBehavoir = new TBulletTextBehavior;
- aBehavoir->IBulletTextBehavior(kBulletTextBehavior, this);
- fBulletTextBehavior = aBehavoir;
- }
-
- TDialogTEView* result = inherited::GetTEView();
-
- if (result) {
- result->AddBehavior(fBulletTextBehavior);
- }
-
- return result;
- } // TBulletEditText::GetTEView
-
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
- pascal void TBulletEditText::GetRealText(CStr255& theText)
- {
- if (fRealDataHandle)
- CopyStr255((**((String255Handle)fRealDataHandle)), (Ptr)&theText);
- else
- theText = gEmptyString;
- } // TBulletEditText::GetRealText
-
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
- pascal void TBulletEditText::ReleaseTEView()
- {
- if (fTEView && fBulletTextBehavior) {
- fTEView->RemoveBehavior(fBulletTextBehavior);
- }
-
- inherited::ReleaseTEView();
- } // TBulletEditText::ReleaseTEView
-
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
- pascal void TBulletEditText::StopEdit()
- {
- if (fTEView)
- {
- CStr255 aString;
-
- fTEView->SetActive(FALSE); // Hides the selection
- this->GetRealText(aString); // Must get the REAL text before removing
- // the floating TEView
- this->RemoveFloatingTEView();
- this->SetText(aString, kDontRedraw);
- }
- } // TBulletEditText::StopEdit
-
- //----------------------------------------------------------------------------------------
- #pragma segment DlgNonRes
- pascal void TBulletEditText::SetText(const CStr255& theText,
- Boolean redraw)
- {
- if (!fRealDataHandle || (CompareStrings(theText,(**((String255Handle)fRealDataHandle))) != 0 )) {
- fRealDataHandle = (CStringHandle)DisposeIfHandle((Handle)fRealDataHandle);
- fRealDataHandle = NewString(theText);
- if (MemError() != noErr)
- fRealDataHandle = NULL;
- }
-
- CStr255 secureText = "";
- for (short i = 1; i <= theText.Length(); i++) {
- secureText += kBulletChar;
- }
-
- if (fTEView) {
- fTEView->SetText(secureText);
- fTEView->RecalcText();
- fTEView->SynchView(kDontRedraw);
- if (redraw && this->IsDrawable()) {
- VRect area;
- CRect qdArea;
-
- this->ControlArea(area);
- this->ViewToQDRect(area, qdArea);
- EraseRect(qdArea);
- this->HandleDraw(area);
- }
- } else {
- if (!fDataHandle || (CompareStrings(secureText,(**((String255Handle)fDataHandle))) != 0 )) {
- this->ReleaseText();
- fDataHandle = NewString(secureText);
- if (MemError() != noErr)
- fDataHandle = NULL;
- if (redraw && this->IsDrawable()) {
- VRect area;
- CRect qdArea;
-
- this->ControlArea(area);
- this->ViewToQDRect(area, qdArea);
- EraseRect(qdArea);
- this->HandleDraw(area);
- }
- }
- }
- } // TBulletEditText::SetText
-
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
- pascal void TBulletEditText::AddCharacter(char ch)
- {
- if (fTEView) {
- TEHandle theHTE = fTEView->fHTE;
- short start = (**theHTE).selStart;
- short end = (**theHTE).selEnd;
-
- CStr255 theText;
- this->GetRealText(theText);
- CStr255 insertText = "";
- insertText += ch;
- if (start - end)
- theText.Delete(start+1, end-start);
- theText.Insert(insertText, start+1);
-
- if (fRealDataHandle) {
- SetString(fRealDataHandle, theText);
- } else {
- fRealDataHandle = (CStringHandle)DisposeIfHandle((Handle)fRealDataHandle);
- fRealDataHandle = NewString(theText);
- if (MemError() != noErr)
- fRealDataHandle = NULL;
- }
- }
- } // TBulletEditText::AddCharacter
-
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
- pascal void TBulletEditText::DelChars()
- {
- if (fTEView) {
- TEHandle theHTE = fTEView->fHTE;
- short start = (**theHTE).selStart;
- short length = (short)Min(kStr255Len, (**theHTE).selEnd - start); //!!! long->short
- if (length == 0) {
- start -= 1;
- length = 1;
- }
-
- if ((start >= 0) && (length > 0)) {
- CStr255 theText;
- this->GetRealText(theText);
- theText.Delete(start+1, length);
-
- if (fRealDataHandle)
- SetString(fRealDataHandle, theText);
- }
- }
- } // TBulletEditText::DelChars
-
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
- pascal void TBulletTextBehavior::IBulletTextBehavior(IDType itsIdentifier, TBulletEditText* itsEditText)
- {
- this->IBehavior(itsIdentifier);
-
- fBulletEditText = itsEditText;
- } // TBulletTextBehavior::IBulletTextBehavior
-
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TBulletTextBehavior::DoCommandKeyEvent(TToolboxEvent* event)
- {
- } // TBulletTextBehavior::DoCommandKeyEvent
-
- //----------------------------------------------------------------------------------------
- #pragma segment DlgRes
- pascal void TBulletTextBehavior::DoKeyEvent(TToolboxEvent* event)
- {
- unsigned char ch = event->fCharacter;
-
- if ((ch >= 0x20) && (ch <= 0x7F)) {
- if (fBulletEditText)
- fBulletEditText->AddCharacter(ch);
- event->fCharacter = kBulletChar;
- } else if (ch > 0x7F) {
- SysBeep(4);
- return;
- } else if (ch == chBackspace) {
- if (fBulletEditText)
- fBulletEditText->DelChars();
- }
-
- inherited::DoKeyEvent(event);
-
- } // TBulletTextBehavior::DoKeyEvent
-
- //----------------------------------------------------------------------------------------
- #pragma segment ASelCommand
- pascal void TBulletTextBehavior::DoMenuCommand(CommandNumber aCommandNumber)
-
- {
- TBehavior * nextBehavior = this->GetNextEnabledBehavior();
-
- if ((aCommandNumber >= cEditBase) && (aCommandNumber <= cEditLast))
- SysBeep(4);
- else
- inherited::DoMenuCommand(aCommandNumber);
- } // TBulletTextBehavior::DoMenuCommand
-
-